package univer.oko.queryAnalizer;

import univer.oko.utilities.CDUtilities;

import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeCellRenderer;
import java.awt.*;

/**
 * Created by Sergey Kharlamov.
 * Date: 16.07.2006
 * Time: 9:57:07
 */

class CDTreeCellRenderer implements TreeCellRenderer {
    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
    private Icon databaseIcon = CDUtilities.createIcon("database.gif");
    private Icon folderOpenIcon = CDUtilities.createIcon("folderopen.gif");
    private Icon folderIcon = CDUtilities.createIcon("folder.gif");
    private Icon viewIcon = CDUtilities.createIcon("view.gif");
    private Icon procedureIcon = CDUtilities.createIcon("procedure.gif");
    private Icon tableIcon = CDUtilities.createIcon("table.gif");

    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {

        JLabel lab = (JLabel) renderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
        Icon icon = null;
        CDTreeNode node = (CDTreeNode) ((DefaultMutableTreeNode) value).getUserObject();
        switch (node.getNodeType()) {
            case Root:
                icon = databaseIcon;

                break;
            case Procedures:
            case Views:
            case Tables:
                if (expanded) {
                    icon = folderOpenIcon;
                } else {
                    icon = folderIcon;
                }
                break;
            case View:
                icon = viewIcon;
                break;
            case Procedure:
                icon = procedureIcon;
                break;
            case Table:
                icon = tableIcon;
        }
        lab.setIcon(icon);
        return lab;
    }
}